﻿
using Microsoft.AspNetCore.Mvc;
using WxProxy.Services;

namespace WxProxy.Controllers
{
    public class ScanController : Controller
    {
        /// <summary>
        ///  获取微信 JS-SDK 服务
        /// </summary>
        private readonly WxJsSdkService _wx;
        public ScanController(WxJsSdkService wx) => _wx = wx;

        public async Task<IActionResult> IndexAsync(string returnUrl)
        {
            var request = HttpContext.Request;
            var url = $"{request.Scheme}://{request.Host}{request.Path}{request.QueryString}";
            var wxConfig = await _wx.GetJsConfigAsync(url);

            ViewBag.ReturnUrl = returnUrl;
            ViewBag.AppID = wxConfig.AppId;
            ViewBag.Timestamp = wxConfig.Timestamp;
            ViewBag.NonceStr = wxConfig.NonceStr;
            ViewBag.Signature = wxConfig.Signature;
            return View();
        }
    }
}